<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/SHA-1.js"></script>
		<script type="text/javascript" src='../../../JS/datagrid-detailview.js'></script>
	</head>

	<body style="padding: 0px;">
		<div class="easyui-layout" style="width:100%;height:500px;">
			<div data-options="region:'center'">
				<div>
					<table id="dg" title="菜单列表" width="100%">
					</table>
				</div>
			</div>
		</div>
		<div id="toolbar"></div>
		<div id="dlg" class="easyui-dialog" closed="true" style="width:600px;height:300px;padding:10px">
			<iframe id="ifrmEdit" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>
		</div>
	</body>
	<script>
		var content = "";
		var AddDialog;
		var DialogHeight = 410;
		var DialogWidth = 400;
		var currRow;
		content = AddToolBar(7);
		$("#toolbar").append(content);
		$(function() {
			$('#dg').datagrid({
				width: 700,
				height: 300
			}).datagrid('subgrid', conf);
		});

		function dialogClose() {
			AddDialog.dialog('close');
		}
		var conf = {
			options: {
				fitColumns: true,
				width: '100%',
				height: 1000,
				toolbar: '#toolbar',
				singleSelect: true,
				url: RemoteLinkAddress + '/menu/getallpMenu.do',
				columns: [
					[{
						field: 'ID',
						title: '编号',
						width: '10%',
						align: 'center'
					}, {
						field: 'MENU_NAME',
						title: '菜单名称',
						width: '10%',
						align: 'center'
					}, {
						field: 'PARENT_ID',
						title: '父节点',
						width: '8%',
						align: 'center'
					}, {
						field: 'MENU_URL',
						title: '菜单地址',
						width: '50%',
						align: 'center'
					}, {
						field: 'MENU_ICON',
						title: '菜单图标',
						width: '15%',
						align: 'center'
					}, ]
				],
				onClickRow: function(index, row) {
					currRow = row;
				},
				onDblClickRow: function(index, row) {
					var pLocation = "UI/Common/Menu/MenuAdd.html?menuid=" + row.ID + "&parentid=" + row.PARENT_ID + "&menutype=" + row.MENU_TYPE;
					$("#ifrmEdit").attr("src", pLocation);
					constructDialog($("#dlg"), "修改", DialogWidth, DialogHeight);
					AddDialog.dialog('open');
				},
			},
			subgrid: {
				options: {
					fitColumns: true,
					singleSelect: true,
					width: '100%',
					url: RemoteLinkAddress + '/menu/sub.do',
					foreignField: 'ID',
					columns: [
						[{
							field: 'ID',
							title: '编号',
							width: '10%',
							align: 'center'
						}, {
							field: 'MENU_NAME',
							title: '菜单名称',
							width: '10%',
							align: 'center'
						}, {
							field: 'PARENT_ID',
							title: '父节点',
							width: '8%',
							align: 'center'
						}, {
							field: 'MENU_URL',
							title: '菜单地址',
							width: '71%',
							align: 'center'
						}, ]
					],
					onClickRow: function(index, row) {
						currRow = row;
					},
					onDblClickRow: function(index, row) {
						var pLocation = "UI/Common/Menu/MenuAdd.html?menuid=" + row.ID + "&parentid=" + row.PARENT_ID + "&menutype=" + row.MENU_TYPE;
						$("#ifrmEdit").attr("src", pLocation);
						constructDialog($("#dlg"), "修改", DialogWidth, DialogHeight);
						AddDialog.dialog('open');
					},
				},
				subgrid: {
					options: {
						fitColumns: true,
						singleSelect: true,
						width: '100%',
						url: RemoteLinkAddress + '/menu/sub.do',
						foreignField: 'ID',
						columns: [
							[{
								field: 'ID',
								title: '编号',
								width: '10%',
								align: 'center'
							}, {
								field: 'MENU_NAME',
								title: '菜单名称',
								width: '10%',
								align: 'center'
							}, {
								field: 'PARENT_ID',
								title: '父节点',
								width: '8%',
								align: 'center'
							}, {
								field: 'MENU_URL',
								title: '菜单地址',
								width: '51%',
								align: 'center'
							},
							{
								field: 'MENU_ORDER',
								title: '菜单模块',
								width: '20%',
								align: 'center'
							},]
						],
						onClickRow: function(index, row) {
							currRow = row;
						},
						onDblClickRow: function(index, row) {
							var pLocation = "UI/Common/Menu/MenuAdd.html?menuid=" + row.ID + "&parentid=" + row.PARENT_ID + "&menutype=" + row.MENU_TYPE;
							$("#ifrmEdit").attr("src", pLocation);
							constructDialog($("#dlg"), "修改", DialogWidth, DialogHeight);
							AddDialog.dialog('open');
						},

					},

				}
			}
		};

		function newdata() {
			var row = currRow;
			if(!row) {
				$.messager.alert('Info', "请选择你需要新增的菜单上级");
				return;
			}
			if(row.MENU_TYPE == 3) {
				$.messager.alert("警告", "不能增加4级菜单");
				return;
			}
			var pLocation = "UI/Common/Menu/MenuAdd.html?menuid=-1&parentid=" + row.ID + "&menutype=" + row.MENU_TYPE;
			$("#ifrmEdit").attr("src", pLocation);
			constructDialog($("#dlg"), "新增", DialogWidth, DialogHeight);
			AddDialog.dialog('open');
		}

		function editdata() {
			var pLocation = '';
			var row = currRow;
			if(!row) {
				$.messager.alert('Info', "请选择你需要修改数据");
				return;
			}
			pLocation = "UI/Common/Menu/MenuAdd.html?menuid=" + row.ID + "&parentid=" + row.PARENT_ID + "&menutype=" + row.MENU_TYPE;
			$("#ifrmEdit").attr("src", pLocation);
			constructDialog($("#dlg"), "修改", DialogWidth, DialogHeight);
			AddDialog.dialog('open');
		}

		function destroy() {
			var row = currRow;
			if(row.PARENT_ID == 0) {
				$.messager.alert("警告", "不能删除一级菜单节点");
				return;
			}
			if(!row) {
				$.messager.alert("警告", "没有选中需要删除的菜单");
				return;
			}
			$.messager.confirm('Confirm', '是否删除', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/menu/delete.do", {
							ID: row.ID,
						},
						function(result) {
							if(result.msg == "success") {
								$('#dg').datagrid('reload'); // reload the user data
								$.messager.alert({ // show error message
									title: '成功',
									msg: '删除成功'
								});
							} else {
								$.messager.alert({ // show error message
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}
	</script>

</html>